package akash.java.code;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class GetPower {
	public static void main(String[] args) throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		System.out.println("Enter the base number :");
		String number1 = reader.readLine();
		System.out.println("Enter the power number :");
		String number2 = reader.readLine();
		StringBuffer base = new StringBuffer(number1);
		StringBuffer power = new StringBuffer(number2);
		Long startTime = System.currentTimeMillis();
		System.out.println("the result of x raised to the power y is :"
				+ getPower(base, power));
		Long endTime = System.currentTimeMillis();
		Long totalTime = endTime-startTime;
		System.out.println(" Time taken by first algo in milliseconds is :" + totalTime );

		System.out
				.println("Now getting same result using devide and conquer method");
         GetPowerByDivideAndConquer gpdc = new GetPowerByDivideAndConquer();
		startTime = System.currentTimeMillis();
		System.out.println("the result of x raised to the power y is :"
				+ gpdc.multiply(base,power));
		endTime = System.currentTimeMillis();
		 totalTime = endTime-startTime;
		System.out.println(" Time taken by Second algo in milliseconds is :" + totalTime );

	}

	private static StringBuffer getPower(StringBuffer base, StringBuffer power) {
		StringBuffer result = new StringBuffer(base.toString());
		LargeMultiply largeMultiply = new LargeMultiply();
		int length = Integer.parseInt(power.toString());
		for (int i = 1; i < length; i++) {
			result = largeMultiply.multiply(base, result);
		}
		return result;
	}
}
